import { _decorator, Component, Node, Prefab,Animation } from 'cc';
import { Healthy } from './Healthy';
const { ccclass, property } = _decorator;

@ccclass('TankAnim')
export class TankAnim extends Component {

    ringAni:Animation=null;
    ani:Animation=null;
    protected onLoad(): void {
        this.ani=this.node.getComponent(Animation);

        this.ringAni=this.node.children[0].getComponent(Animation);
        this.ringAni.node.active=false;
        /*
        this.node.children[1].active=true;
        this.scheduleOnce(()=>{
            this.node.children[1].active=false;
        },1);
        */

        this.node.on("CHANGE_MOVE_STATE",this.playMoveAnim,this);
    }
    protected onDestroy(): void {
        this.node.off("CHANGE_MOVE_STATE",this.playMoveAnim,this);
    }

    playMoveAnim(arg:boolean){

        if(this.ani){
           // console.log("play tank move anim"+typeof arg);
         // this.ani.stop();
         if(arg){

             this.ani.play();
         }else{

             this.ani.stop();
         }
        }
    }

    toggleRing(isShow:boolean){
        this.ringAni.node.active=isShow;
    }
}


